"""
https://www.lintcode.com/problem/search-range-in-binary-search-tree/description
11. 二叉查找树中搜索区间
给定两个值 k1 和 k2（k1 < k2）和一个二叉查找树的根节点。找到树中所有值在 k1 到 k2 范围内的节点。即打印所有x (k1 <= x <= k2) 其中 x 是二叉查找树的中的节点值。返回所有升序的节点值。

样例
如果有 k1 = 10 和 k2 = 22, 你的程序应该返回 [12, 20, 22].

    20
   /  \
  8   22
 / \
4   12
"""

"""
Definition of TreeNode:
class TreeNode:
    def __init__(self, val):
        self.val = val
        self.left, self.right = None, None
"""

class Solution:
    """
    @param root: param root: The root of the binary search tree
    @param k1: An integer
    @param k2: An integer
    @return: return: Return all keys that k1<=key<=k2 in ascending order
    """
    def searchRange(self, root, k1, k2):
        # write your code here
        self.range = []
        if root == None:
            return []
        self.midRootSearch(root, k1, k2)
        return self.range
    def midRootSearch(self, root, k1, k2):
        if root.left:
            self.midRootSearch(root.left, k1, k2)
        if  k1 <= root.val <= k2:
            self.range.append(root.val)
        elif root.val > k2:
            return
        if root.right:
            self.midRootSearch(root.right, k1, k2)